package com.maizhe.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.maizhe.dao.*;
import com.maizhe.entity.*;
import com.maizhe.entity.vo.UserVo;
import com.maizhe.service.CustomerService;
import com.maizhe.service.UserService;
import com.maizhe.util.JsonResult;
import com.maizhe.util.UUIDGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class CustomerServiceImpl implements CustomerService {
	
	@Autowired
	private CustomerMapper customerMapper;

	public PageInfo<Customer> findAll(Customer customer,UserVo user) {
		PageHelper.startPage(customer.getPage(),customer.getRows());
		List<Customer>list=customerMapper.findAll(customer);
		return new PageInfo<Customer>(list);
	}

	public int delete(String id) {
		return customerMapper.delete(id);
	}

	public Customer findById(String id) {
		return  customerMapper.findById(id);
	}

	public int savecustomer(Customer customer) {
		int k=0;
		if (customer.getId()!=null && !"".equalsIgnoreCase(customer.getId())) {//编辑
			return  customerMapper.chg(customer);
		}else {//新增
			customer.setId(UUIDGenerator.getUUID());
			customer.setState("启动");
			k=customerMapper.save(customer);
			return k;
		}
	}

	public List<Customer> findAll() {
		return customerMapper.findAll(new Customer());
	}

}
